package com.kongjs.common.datasource.component;

import jakarta.annotation.Resource;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.stereotype.Component;


@Component
public class DynamicDataSourceRemover {

    @Resource
    private ConfigurableListableBeanFactory beanFactory;

    public void removeDataSource(String beanName) {
        // 将 ConfigurableListableBeanFactory 转换为 DefaultListableBeanFactory
        DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) beanFactory;
        // 从 Bean 工厂中移除 Bean 定义
        defaultListableBeanFactory.removeBeanDefinition(beanName);
    }
}
